/*
 * @Description: 函数与指针
 * @Version: 1.0
 * @Author: marshal
 * @Date: 2022-06-28 09:36:50
 * @LastEditors: marshal
 * @LastEditTime: 2022-06-28 14:10:32
 */
#include <stdio.h>

// 定义一个函数指针
typedef int (*pfun)(int, int);

int sum(int, int);

int calculate(int, int, pfun);

int main(int argc, char const *argv[])
{
    // 求和
    int result = calculate(10, 20, sum);
    printf("sum = %d\n", result);
    return 0;
}

int sum(int a, int b)
{
    return a + b;
}

/**
 * @brief 计算
 *
 * @param a 参数a
 * @param b 参数b
 * @param operation  计算方法
 * @return int 计算值
 */
int calculate(int a, int b, pfun operation)
{
    int sum = operation(a, b);
    return sum;
}